Shader "Sample/GenShadowMap"
{
    Properties
    {
        //_MainTex ("Texture", 2D) = "white" {}
        //_gShadowBias("_gShadowBias",Float)=1
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        //LOD 100
        
        Pass
        {
            //Cull Off ZWrite On ZTest LEqual
            CGPROGRAM
// Upgrade NOTE: excluded shader from DX11; has structs without semantics (struct v2f members depth)
//#pragma exclude_renderers d3d11
// Upgrade NOTE: excluded shader from DX11; has structs without semantics (struct v2f members depth)
//#pragma exclude_renderers d3d11
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            //#pragma multi_compile_fog

            #include "UnityCG.cginc"

            uniform float _gShadowBias;
			uniform float _gShadowNormalBias;//无用
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float3 normal:NORMAL;
                
            };

            struct v2f
            {
                //float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
                //float3 normal:NORMAL;
                //float4 shadowCoord:TEXCOORD1;
                //float3 worldPos:TEXCOORD2;
                float2 depth:TEXCOORD0;
            };

            //sampler2D _MainTex;
            //float4 _MainTex_ST;

           v2f vert (appdata v)
            {
                v2f o;
                o.vertex = mul(unity_ObjectToWorld, v.vertex);
				float3 normal = normalize(mul(v.normal, unity_WorldToObject));
				//o.vertex.xyz -= normal * _gShadowNormalBias;
				o.vertex = UnityWorldToClipPos(o.vertex);
#if defined(SHADER_TARGET_GLEL)
				o.vertex.z += _gShadowBias * 2;
#elif defined(UNITY_REVERSED_Z)
				o.vertex.z -= _gShadowBias;
#else
				o.vertex.z += _gShadowBias;
#endif
				o.depth = o.vertex.zw;
                return o;
            }
 
            float4 frag (v2f i) : SV_Target
            {
				float depth = i.depth.x / i.depth.y;
#if defined(SHADER_TARGET_GLEL)
				depth = depth * 0.5 + 0.5;
#elif defined(UNITY_REVERSED_Z)
				depth = 1 - depth;
#endif
				return depth;
 
                //return EncodeFloatRGBA(depth);
            }
            ENDCG
        }
        
    }
    FallBack "Diffuse"
}
